<% layout("/layouts/micro.html"){ %>
<div class="childrenBody">
	<div class="kit-table">
		<form class="layui-form">
			<div class="kit-table-header">
				<div class="kit-search-btns">
					<%if(shiro.hasPermission("sys:openOauth:edit")){%>
					<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
					<%}%>
				</div>
			</div>
		</form>
		<div class="kit-table-body">

			<table id="openOauthList" lay-filter="openOauthList"></table>

			<!--操作-->
			<script type="text/html" id="openOauthListBar">
				<!--<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
				<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
				<!--<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>-->
			</script>
		</div>
	</div>
</div>

<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //列表
        var tableIns = table.render({
            elem: '#openOauthList',
            url : '${ctx}/sys/openOauth/listAjax',
            cellMinWidth : 95,
            page : true,
            request: {
                pageName: 'pageNo', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            height : "full-70",
            limit : 15,
            limits : [10,15,20,25],
            id : "openOauthListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
                	{field:'userNameLabel', title: '用户姓名'},
					{field:'oauthTypeLabel', title: '认证类型'},
				<%if(shiro.hasPermission("sys:openOauth:edit")){%>
					{title: '操作', width:170, templet:'#openOauthListBar',fixed:"right",align:"center"}
			 	<%}%>
            ]]
        });

        //搜索
        $(".search_btn").on("click",function(){
			table.reload("openOauthListTable",{
				page: {
					curr: 1 //重新从第 1 页开始
				},
				where: {
				}
			})
        });

        //添加
        function addopenOauth(id){
            var index = layui.layer.open({
                title : "添加认证信息管理",
                type : 2,
                content : "${ctx}/sys/openOauth/form?id="+id,
                area: ['90%', '80%']
            })
        }
        $(".addopenOauth_btn").click(function(){
            var id = '${openOauth.id}';
            addopenOauth(id);
        })


        //批量删除
        $(".delAll_btn").click(function(){
            var checkStatus = table.checkStatus('openOauthListTable'),
                data = checkStatus.data,
                selectedIds = [];
            if(data.length > 0) {
                for (var i in data) {
                    selectedIds.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("${ctx}/sys/openOauth/batchDelete",{selectedIds:selectedIds.join(",")},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                })
            }else{
                layer.msg("请选择需要删除的数据");
            }
        })

        //列表操作
        table.on('tool(openOauthList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;

            if(layEvent === 'edit'){ //编辑
                addopenOauth(data.id);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除选中数据？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/sys/openOauth/delete",{id:data.id},function(result){
                        if(result.code=="0"){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'look'){ //预览
                layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
            }
        });

    })
</script>
<%}%>